<?php

class NTreeHelper{


	function _makeSelBoxOptions(&$oTree,$fieldName, $selected, $key, &$ret, $prefix_orig, $prefix_curr = '')	{
	
	$_myId=$oTree->_myId;
        if ($key > 0 and $oTree->_tree[$key]['obj']->$fieldName) {
            $value = $oTree->_tree[$key]['obj']->$_myId;
            $ret .= '<option value="'.$value.'"';
			if ($value == $selected) {
				$ret .= ' selected="selected"';
			}
			$ret .= '>'.$prefix_curr.$oTree->_tree[$key]['obj']->$fieldName.'</option>';
            $prefix_curr .= $prefix_orig;
        }
        if (isset($oTree->_tree[$key]['child']) && !empty($oTree->_tree[$key]['child'])) {
            foreach ($oTree->_tree[$key]['child'] as $childkey) {
                NTreeHelper::_makeSelBoxOptions($oTree,$fieldName, $selected, $childkey, $ret, $prefix_orig, $prefix_curr);
            }
        }
	}
	

	function &makeSelBox($oTree,$name, $fieldName, $prefix='-', $selected='', $addEmptyOption = false, $key=0)
    {
        $ret = '<select name="'.$name.'" id="'.$name.'">';
        if (false != $addEmptyOption) {
            $ret .= '<option value="">'.$addEmptyOption.'</option>';
        }
        NTreeHelper::_makeSelBoxOptions($oTree,$fieldName, $selected, $key, $ret, $prefix);
       	$ret .= '</select>';
        return $ret;
    }
	

}


?>